//
//  DBJPhotographView.m
//  DBJ
//
//  Created by 花化华 on 2016/11/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "DBJPhotographView.h"
#import "SDCycleScrollView.h"
#import <Masonry.h>
#import "DBJNetworkTool.h"
#import <YYModel.h>
#import "DBJPhotographModel.h"

@interface DBJPhotographView () <SDCycleScrollViewDelegate>

/** 数据模型 */
@property (nonatomic,strong) NSArray *photographModels;

@end

@implementation DBJPhotographView

- (void)dbjSetupSubviews{
    [super dbjSetupSubviews];
    //获取数据
    [[DBJNetworkTool sharedNetworkTool] POSTWithURLString:@"http://iosapi.itcast.cn/doctor/banners.json.php" parameters:@{@"page_size" : @10, @"page" : @1} success:^(id responseObject) {
        
        //反序列化
        NSDictionary *responseData = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:NULL];
//        NSLog(@"%@",responseData);
        NSDictionary *resultDidct = responseData[@"data"];
        NSArray *result = resultDidct[@"banners"];
        
        //转成模型数组
        _photographModels = [NSArray yy_modelArrayWithClass:[DBJPhotographModel class] json:result];
        
        NSMutableArray *imagesURLStrings = [NSMutableArray array];
        for (int i = 0; i < _photographModels.count; i++) {
            DBJPhotographModel *imgModel = _photographModels[i];
            [imagesURLStrings addObject:imgModel.banner_img_url];
        }
        
        //创建SDCycleScrollView
        SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
        cycleScrollView3.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
        cycleScrollView3.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
        cycleScrollView3.imageURLStringsGroup = imagesURLStrings;
        [self addSubview:cycleScrollView3];
        
        //约束
        [cycleScrollView3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
    } faile:^(NSError *error) {
        NSLog(@"网络请求失败：%@",error);
    }];

}

@end
